use tokio::sync::mpsc;

use bc_base::{PublicKeyHashBytes, TransactionId, transaction::Transaction};

#[derive(Debug)]
pub struct MiningManager {
    command_sender: mpsc::Sender<MiningCommand>,
    transaction_sender: mpsc::Sender<Transaction>,
}

#[derive(Debug)]
pub enum MiningCommand {
    Start(PublicKeyHashBytes),
    Pause,
    Stop,
    DeleteTx(TransactionId),
    GenBlockWhenReceiveTx(bool), // if true, generate block immediately when receive tx
    StartMiningImmediately,
}

impl MiningManager {
    pub fn new() -> (
        Self,
        mpsc::Receiver<MiningCommand>,
        mpsc::Receiver<Transaction>,
    ) {
        let (command_sender, command_receiver) = mpsc::channel(5);
        let (transaction_sender, transaction_receiver) = mpsc::channel(5);
        (
            MiningManager {
                command_sender,
                transaction_sender,
            },
            command_receiver,
            transaction_receiver,
        )
    }

    pub fn get_mining_command_sender(&self) -> mpsc::Sender<MiningCommand> {
        self.command_sender.clone()
    }

    pub fn get_transaction_sender(&self) -> mpsc::Sender<Transaction> {
        self.transaction_sender.clone()
    }
}
